package com.prim.threadcoreknowledge.sixstater;

/**
 * 展示线程 New Runnable Terminated 状态
 * 即使正在运行也是Runnable状态，而不是Running
 *
 * @author prim
 */
public class NewRunnableTerminated implements Runnable {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new NewRunnableTerminated());
        //New 状态
        System.out.println(thread.getState().toString());
        thread.start();
        //Runnable 状态
        System.out.println(thread.getState().toString());
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //Runnable 状态 即使是正在运行也是Runnable而不是Running
        System.out.println(thread.getState().toString());
        Thread.sleep(100);
        //打印出Terminated状态
        System.out.println(thread.getState().toString());
    }

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println(i);
        }
    }
}
